package com.freemyleft.left.left_app.mian.index.my.MyRanking.adapter;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.freemyleft.left.zapp.ui.recycler.DataConverter;
import com.freemyleft.left.zapp.ui.recycler.MultipleFields;
import com.freemyleft.left.zapp.ui.recycler.MultipleItemEntity;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import java.util.ArrayList;

import static com.freemyleft.left.left_app.mian.index.my.MyRanking.adapter.MyRankingAdapter.MY_RANKING_tYPE;

public class MyRankingConvert extends DataConverter {
    ArrayList<MultipleItemEntity> entities = new ArrayList<>();

    @Override
    public ArrayList<MultipleItemEntity> convert() {
        JSONObject object = JSONObject.parseObject(getJsonData());
        JSONObject result = object.getJSONObject("result");
        JSONArray list = result.getJSONArray("list");
        int size = list.size();
        for (int i = 0; i < size; i++) {
            JSONObject object1 = list.getJSONObject(i);
            String ranKing = object1.getString("ranking");
            String nikeName = object1.getString("cardname");
            String score = object1.getString("credit");
            String photo = object1.getString("head");
            MultipleItemEntity entity = MultipleItemEntity.builder()
                    .setField(MultipleFields.ITEM_TYPE, MY_RANKING_tYPE)
                    .setField(MyRankingAdapter.MyRankingFiles.PHOTO, photo)
                    .setField(MyRankingAdapter.MyRankingFiles.RANKING, ranKing)
                    .setField(MyRankingAdapter.MyRankingFiles.NIKENAME, nikeName)
                    .setField(MyRankingAdapter.MyRankingFiles.SCORE, score).build();
            entities.add(entity);
        }
        return entities;
    }
}